package lxx.pandams.adapter;

import lxx.pandams.R;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class GridViewAdapter extends BaseAdapter{
	
	private String[] title;
	private int[] photoId;
	private Context ctx;
	
	public GridViewAdapter(Context ctx,String[] title,int[] photoId){
		this.title = title;
		this.photoId = photoId;
		this.ctx = ctx;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return title.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return title[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = View.inflate(ctx, R.layout.gridview_item, null);
		TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
		ImageView iv_icon = (ImageView) view.findViewById(R.id.iv_icon);
		
		tv_title.setText(title[position]);
		iv_icon.setBackgroundResource(photoId[position]);
		
		return view;
	}

}
